はじめまして、Java初心者で、Processingを使っているものです。どうぞよろしくお願いします。
Processingで、Twitter4jとJSONを一緒に使おうとすると"The type JSONArray is ambiguous"というエラーが出るのですが、調べていたら、
JSONArray json = new JSONArray();
JSONArray hobby;
と記述していたものを
processing.data.JSONArray json = new JSONArray();
processing.data.JSONArray hobby;
に書き変えましたが、JSONArrayの行に
"The type JSONArray is ambiguous"というエラーが出てしまいます。processing.data.を付ける以外に解決方法はあるのでしょうか?(Javaで書いてProcessingで読み込む方がよいのでしょうか?)アドバイス頂けると助かります。
コードは下記です。
import twitter4j.*;
import twitter4j.conf.*;
Twitter twitter;
String consumer_key = "コンシューマーキー";
String consumer_secret = "コンシューマーシークレット";
String oauth_token = "オース";
String oauth_token_secret = "オースシークレット";
PImage icon = null;
String tweet = "";
String user_name = "ユーザー名";
void setup() {
size(640, 480);
PFont myFont = createFont("Osaka", 48);
textFont(myFont);
processing.data.JSONArray json = new JSONArray();
processing.data.JSONArray hobby;
// son
processing.data.JSONObject son = new JSONObject();
son.setInt("age",21);
son.setString("name","son");
hobby = new JSONArray();
hobby.append("baseball");
hobby.append("car");
son.setJSONArray("hobby",hobby);
// 配列に個人情報オブジェクトを追加
json.append(son);
// data/person.json に保存
saveJSONArray(json,"data/person.json");
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(consumer_key)
.setOAuthConsumerSecret(consumer_secret)
.setOAuthAccessToken(oauth_token)
.setOAuthAccessTokenSecret(oauth_token_secret);
TwitterFactory tf = new TwitterFactory(cb.build());
twitter = tf.getInstance();
try {
ResponseList<Status> statuses = twitter.getMentionsTimeline();
if (statuses.size() > 0) {
tweet = statuses.get(4).getText();
}
} catch(TwitterException e) {
println(e.getStatusCode());
}
noLoop();
}
void draw() {
background(128);
translate(width / 2, height / 2);
//tweetを分割
drawTweet(tweet);
}
void drawTweet(String tweet_text) {
pushMatrix();
noStroke();
background(255);
fill(0, 0, 0);
textSize(24);
translate(0, 0, 1);
text(tweet_text, -200, -40, 400, 200);
popMatrix();
}