Processingで、Twitter4jとJSONを一緒に使おうとすると"The type JSONArray is ambiguous"というエラーが出る件について

141 views
Skip to first unread message

aua jo

unread,
Oct 7, 2014, 12:01:59 AM10/7/14
to twitt...@googlegroups.com
はじめまして、Java初心者で、Processingを使っているものです。どうぞよろしくお願いします。
Processingで、Twitter4jとJSONを一緒に使おうとすると"The type JSONArray is ambiguous"というエラーが出るのですが、調べていたら、
下記のサイトに解決方法があったため
http://tsujimotter.hatenablog.com/entry/2013/10/02/215806

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();
}

Makoto Yamazaki

unread,
Oct 7, 2014, 12:11:58 AM10/7/14
to twitt...@googlegroups.com
zaki です。

とりあえずエラーを出なくするというだけなら

processing.data.JSONArray json = new JSONArray();


processing.data.JSONArray json = new processing.data.JSONArray();

にすれば解決するような気がします。

--
Twitter4J の最新情報をフォロー: http://twitter.com/t4j_news
現在のバージョン - 安定: 4.0.1, 開発中: 4.0.2-SNAPSHOT
バグトラッキング: http://issue.twitter4j.org/youtrack/issues/TFJ
 
このメールは次の Google グループの参加者に送られています: Twitter4J J
このグループにメールで投稿: twitt...@googlegroups.com
このグループから退会する: http://groups.google.com/group/twitter4j-j?hl=ja
---
このメールは Google グループのグループ「Twitter4J J」に登録しているユーザーに送られています。
このグループから退会し、グループからのメールの配信を停止するには twitter4j-j...@googlegroups.com にメールを送信してください。
その他のオプションについては https://groups.google.com/d/optout にアクセスしてください。



--
YAMAZAKI Makoto

aua jo

unread,
Oct 7, 2014, 10:59:25 AM10/7/14
to twitt...@googlegroups.com
zakiさん、どうもありがとうございます!
言われた通り、
newの方もすべてprocessing.data.を付ける事で解決しました。
とても助かりました!

aua



2014年10月7日火曜日 13時11分58秒 UTC+9 Makoto Yamazaki:
<span style="color:rgb(17,17,17);font-family:メイリオ,'Hiragino Kaku Gothic Pro',Meiryo,'\0030d2\0030e9\0030ae\0030ce\0089d2\0030b4Pro W3',&#3
...

Yamamoto Yusuke

unread,
Oct 7, 2014, 11:01:57 AM10/7/14
to twitt...@googlegroups.com
new JSONArray();の JSONArrayが processing.data.JSONArrayを指すのかtwitter4j.internal.json.JSONArrayを指すのかが曖昧(ambiguous)というコンパイルエラーですね。

Twitter4Jはバージョン4.0から twitter4j.internal.* パッケージが無くなっています。
おそらくバージョン3.0.xをお使いかと思いますので最新版に移行していただければ!
--
山本 裕介
@yusuke
http://samuraism.jp/

aua jo

unread,
Oct 7, 2014, 11:29:23 AM10/7/14
to twitt...@googlegroups.com
山本 裕介さま

どうもありがとうございます
twitter4j-4.0.3-SNAPSHOT.zip / JavaDoc をダウンロードして入れ替えてみたのですが、
やはりThe type JSONArray is ambiguous"エラーが出ました。
(何かやり方を間違えているでしょうか?)
参考にしたのは下記のサイトです。

aua





2014年10月8日水曜日 0時01分57秒 UTC+9 yus...@mac.com:

Yamamoto Yusuke

unread,
Oct 7, 2014, 11:41:16 AM10/7/14
to twitt...@googlegroups.com
なるほど。するとTwitter4J以外にJSONArrayを含むライブラリがクラスパスに入っていることになりますね。

とりあえず解決しているので突っ込んで調べる必要はなさそうですが・・・
--
山本 裕介
@yusuke
http://samuraism.jp/

aua jo

unread,
Oct 7, 2014, 12:54:22 PM10/7/14
to twitt...@googlegroups.com
山本さま

お返事ありがとうございます

なるほど。するとTwitter4J以外にJSONArrayを含むライブラリがクラスパスに入っていることになりますね。


あと先ほど書いた参考URLが間違っていました、、
でした。申し訳ありません。
この中に、Google 先生によると、twitter4j for processingというものがあるようです。という記述があるのですが
もしかすると、入れ替えていないファイルが1つあったのですがそれが原因かもしれないと思いました。
(添付画像の twitter4j.jar です。)

明日もう少し調べてみようと思います。


aua


irekae.png
Reply all
Reply to author
Forward
0 new messages